package com.adrian.misc.fractal.color;

import java.awt.Color;

public class TriColorColorMap extends ColorMap {
	Color[] colTable;
	
	public TriColorColorMap (String name, Color baseCol, Color startCol,Color midCol, Color endCol,double split ,int res) {
		super(name);
		this.baseCol = baseCol;
		resolution = res;
		colTable = new Color[res];
		
		double rInc1 = ((double)(midCol.getRed() - startCol.getRed()))/(double)(res*split);
		double gInc1 = ((double)(midCol.getGreen() - startCol.getGreen()))/(double)(res*split);
		double bInc1 = ((double)(midCol.getBlue() - startCol.getBlue()))/(double)(res*split);
		double rInc2 = ((double)(endCol.getRed() - midCol.getRed()))/(double)(res*(1-split));
		double gInc2 = ((double)(endCol.getGreen() - midCol.getGreen()))/(double)(res*(1-split));
		double bInc2 = ((double)(endCol.getBlue() - midCol.getBlue()))/(double)(res*(1-split));
		System.out.println("StartCol:" + startCol + "," + endCol);
		System.out.println("Building color table: "+ res+"," + rInc1 + "," +gInc1 +"," + bInc1);
		System.out.println("Building color table: "+ res+"," + rInc2 + "," +gInc2 +"," + bInc2);
		for (int i= 0; i < (res*split); i++) {
			//System.out.println("Color:" +i);
			colTable[i] = new Color((int)(startCol.getRed() +i * rInc1),
									(int)(startCol.getGreen() + i * gInc1),
									(int)(startCol.getBlue() + i * bInc1) );
		}
		for (int i=0; i < (int)(res*(1-split)); i++) {
			System.out.println("part2 Color:" +i);
			colTable[(int)(res*split)+i] = new Color((int)(midCol.getRed() +i * rInc2),
									(int)(midCol.getGreen() + i * gInc2),
									(int)(midCol.getBlue() + i * bInc2));
		}

	}



	public Color getColor(double val) {
		//double normVal = func(val);
		double normVal = val;
		int num =  (int)( normVal * resolution);
		if ( num >= resolution) {
			return baseCol;
		}
		return colTable[num];
	}


}
